﻿using Microsoft.AspNetCore.Mvc;
using MVC_System.DTO.WXTWorker;
using Newtonsoft.Json;
using WMS_MAV;

namespace MVC_System.Controllers
{
    public class WorkerController : Controller
    {
        private readonly IConfiguration _configuration;

        public WorkerController(IConfiguration configuration)
        {
            _configuration = configuration;
        }
        /// <summary>
        /// 工人显示视图
        /// </summary>
        /// <returns></returns>
        public IActionResult WorkerShow()
        {
            return View();
        }
        /// <summary>
        /// 工人显示
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// 
        [HttpGet]
        public async Task<ActionResult> GetShowWorker(WorkerShowDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "/api/Worke/WorkeShow?pageIndex=" + dto.pageIndex + "&pageSize=" + dto.pageSize + "&workerNumbering=" + dto.workerNumbering + "&workerName=" + dto.workerName + "&workerState=" + dto.workerState;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        /// <summary>
        /// 工人添加
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<ActionResult> GetAddWorker(WorkerAddDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "/api/Worke/WorkeAdd";
            var respomse = await client.PostAsync(url, dto.Data);
            return Json(respomse);
        }
        /// <summary>
        /// 工人删除
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<ActionResult> GetDeleteWorker(WorkerDeleteDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper (dto.Token);
            string url = _configuration["Url"] + "/api/Worke/WorkeDelete";
            var response = await client.PostAsync(url, dto.Data);
            return Json(response);
        }
        /// <summary>
        /// 工人反填
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// 
        [HttpGet]
        public async Task<ActionResult> GetBackFillWorker(WorkerBackFillDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "/api/Worke/WorkeBackFill?workerId="+dto.workerId;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 工人修改
        /// </summary>
        /// <param name="obj1"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<ActionResult> GetUpdateWorker(WorkerUpdateDTO obj1,string token)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "/api/Worke/WorkeUpdate";
            string list = JsonConvert.SerializeObject(obj1);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }


    }
}
